#include "sq_list.h"
#include "../test.h"

void test(){
	void *ep;
	sq_list mylist;
	struct mydata elem = {18,'z'},ee = {14,'e'}, e0,
		e1 = {19,'a'},e2 = {18,'z'},e3 = {1,'s'}, e4 = {9,'k'};

	sqlist_init(&mylist, sizeof(struct mydata));

	sqlist_insert(&mylist, 1, (void *) &e1, sizeof(struct mydata));
	sqlist_insert(&mylist, 2, (void *) &e2, sizeof(struct mydata));
	sqlist_insert(&mylist, 2, (void *) &e3, sizeof(struct mydata));
	sqlist_insert(&mylist, 2, (void *) &e4, sizeof(struct mydata));
	
	//sqlist_clear(&mylist);
	//sqlist_destroy(&mylist);
	//printf("%d\n",sqlist_empty(&mylist));
	//printf("%d\n",sqlist_length(&mylist));

	//visit(sqlist_getelem(&mylist, 0, sizeof(struct mydata)));
	//ep = sqlist_getelem(&mylist, 2, sizeof(struct mydata));
	
/*	printf("%d,%c,,,,,,\n",(*(struct mydata*)ep).value,
				(*(struct mydata*)ep).ch);
*/

//	printf("%d,,,...,.\n",sqlist_locateelem(&mylist,(void *)&elem, my_compare,sizeof(struct mydata)));

	sqlist_traverse(&mylist, visit, sizeof(struct mydata));

	sqlist_delete(&mylist, 4, (void *)&e0,sizeof(struct mydata));
	visit((void *)&e0);

	printf("%d\n",sqlist_length(&mylist));
	sqlist_traverse(&mylist, visit, sizeof(struct mydata));
}

void test2()
{
	sq_list sa,sb,sc;
	struct mydata elem;
	int i;
	sqlist_init(&sa, sizeof(struct mydata));
	sqlist_init(&sb, sizeof(struct mydata));
	srand(343);
	for(i = 0; i < 11; i++){
		//elem.value = rand()%10;
		elem.value = i*2;
		elem.ch = 'a';
		sqlist_insert(&sa,i+1,(void *)&elem, sizeof(struct mydata));
		//elem.value = rand()%10;
		elem.value = i*2+10;
		elem.ch = 'b';
		sqlist_insert(&sb,i+1,(void *)&elem, sizeof(struct mydata));
	}
	sqlist_delete(&sa, 3 , (void *) &elem, sizeof(struct mydata));
	sqlist_traverse(&sa,visit,sizeof(struct mydata));
	sqlist_traverse(&sb,visit,sizeof(struct mydata));
	sqlist_merge(&sa,&sb,&sc,my_compare,sizeof(struct mydata));
	sqlist_traverse(&sc,visit,sizeof(struct mydata));
}

int main(){
	test2();
}

